package org.example.mall.Service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.mall.Mapper.UsersMapper;
import org.example.mall.Pojo.Users;
import org.example.mall.Service.UsersService;
import org.example.mall.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

//面向功能
@Slf4j
@Service
public class UsersServiceimpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;

    @Override
    public Users findByUsername(String Username) {
        Users u = usersMapper.F_U_name(Username);
        return u;
    }

    @Override
    public void register(String Username, String Password) {
        //加密
        String md5String = Md5Util.getMD5String(Password);
        //添加
        log.info("Service层注册："+Username);
        usersMapper.add(Username,md5String);
    }

    @Override
    public void update(Users user){
        user.setUpdateTime(LocalDateTime.now());
        usersMapper.update(user);
    }

    @Override
    public void UpdateAvatar(String avatarUrl,Integer Id) {
        log.info("更新头像url："+avatarUrl+" Id："+Id);
        usersMapper.UpdateAvatar(avatarUrl,Id);
    }

    @Override
    public void UpdatePwd(String newPwd,Integer Id) {
        //加密
        String md5String = Md5Util.getMD5String(newPwd);
        //修改
        usersMapper.UpdatePwd(md5String,Id);
    }
}
